# frozen_string_literal: true

FactoryBot.define do
  factory :rule_entity do
    rule
    schema { nil }
    type do
      rule.is_a?(Rule::GeneralRule) ? RuleEntity::GeneralRule::Condition::All : rule.type.sub(/^Rule:/, 'RuleEntity:')
    end
    status { RuleEntity::Status::CREATED }
    stage { RuleEntity::Stage::DRAFT }
    policy { RuleEntity::Policy::ALL }
    version { 0 }

    # status
    trait :created do
      status { RuleEntity::Status::CREATED }
    end
    trait :validated do
      status { RuleEntity::Status::VALIDATED }
    end
    trait :deployed do
      status { RuleEntity::Status::DEPLOYED }
    end

    # stage
    trait :draft do
      stage { RuleEntity::Stage::DRAFT }
    end
    trait :product do
      stage { RuleEntity::Stage::PRODUCT }
    end

    # policy
    trait :first do
      policy { RuleEntity::Policy::FIRST }
    end
    trait :all do
      policy { RuleEntity::Policy::ALL }
    end

    # factory
    factory :rule_entity_rule_set, class: 'RuleEntity::RuleSet' do
      type { RuleEntity::RuleSet }
    end
    factory :rule_entity_decision_table, class: 'RuleEntity::DecisionTable' do
      type { RuleEntity::DecisionTable }
    end
    factory :rule_entity_general_rule_dsl, class: 'RuleEntity::GeneralRule::Dsl' do
      type { RuleEntity::GeneralRule::Dsl }
    end
    factory :rule_entity_general_rule_condition_all, class: 'RuleEntity::GeneralRule::Condition::All' do
      type { RuleEntity::GeneralRule::Condition::All }
    end
    factory :rule_entity_general_rule_condition_any, class: 'RuleEntity::GeneralRule::Condition::Any' do
      type { RuleEntity::GeneralRule::Condition::Any }
    end
    factory :rule_entity_general_rule_condition_dsl, class: 'RuleEntity::GeneralRule::Condition::Dsl' do
      type { RuleEntity::GeneralRule::Condition::Dsl }
    end
  end
end
